home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
tos.arc
/
minix.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-08
|
3KB
|
122 lines
/*
* Load and start MINIX on the Atari ST while running TOS.
* The MINIX loadfile can be a GEMDOS file or a floppy disk,
* so that we read only blocks of 512 bytes.
* The MINIX loadfile has a format similar to MINIX-PC.
*/
#include "fakeunix.c"
long size;
char *minix = "minix.img";
char blk0[512];
main(argc,argv)
char **argv;
{
register fd;
register long n, j;
register i;
register char *p;
register char *bminix;
unsigned short *wp;
int kick();
int (*pc)();
if (argc > 1)
minix = argv[1];
if ((fd = open(minix, 0)) < 0)
fatal("cannot open %s", minix);
if ((i = read(fd, blk0, (int)sizeof(blk0))) != (int)sizeof(blk0))
fatal("read block 0 failed (ask %d, ret %d)", (int)sizeof(blk0), i);
wp = (unsigned short *)&blk0[(int)sizeof(blk0)];
if (wp[-2] != 0 || wp[-3] != wp[-1])
fatal("%s: wrong format", minix);
size = wp[-4] * 512L;
size += 1000L;
#ifdef __GNUC__
p = (char *)Malloc(size); /* Malloc with long size */
#else
p = (char *)gemdos(0x48,size); /* Malloc with long size */
#endif
if ((long)p <= 0)
fatal("malloc failed\n");
bminix = p;
for (i = 0; (j = wp[-16+2*i]) != 0; i++) {
j *= 512L;
#ifdef __GNUC__
n = Fread( fd, j, p); /* Fread with long size */
#else
n = gemdos(0x3f, fd, j, p); /* Fread with long size */
#endif
if (n != j)
fatal("read failed (ask %ld, ret %ld)", j, n);
p += j;
j = wp[-15+2*i] * 512L;
while (j--)
*p++ = '\0';
}
/*
* copy kick() (and some more) at the end of minix
* we have to avoid overwriting kick()
*/
memcopy(p, (char *)kick, 1000);
#ifdef __GNUC__
Super(0L); /* Super */
#else
gemdos(0x20,(char *)0); /* Super */
#endif
spl7();
pc = (int (*)())p;
(*pc)(bminix, p);
}
spl7()
{
int (*pc)();
static short code[] = {
0x007C, /* or.w #0x700,sr */
0x0700,
0x4E75, /* rts */
};
pc = (int (*)())code;
(*pc)();
}
memcopy(s1, s2, n) register char *s1, *s2; register n; {
while (--n >= 0)
*s1++ = *s2++;
}
kick(bminix, eminix)
register char *bminix; /* begin of minix as read in */
register char *eminix; /* end of minix as read in */
{
register char *lowmem; /* copy it to low core */
register long bootpc; /* at offset 4: start address */
register int (*pc)(); /* same but casted to func */
bminix += 4;
bootpc = ((long *)bminix)[0];
bminix += 4;
lowmem = ((char *)8);
while ((long)lowmem < 0x0400) /* don't clobber TOS vars */
*lowmem++ = *bminix++;
lowmem += 0x0200; /* length of TOS area */
bminix += 0x0200;
while (bminix < eminix)
*lowmem++ = *bminix++;
pc = (int (*)())bootpc;
(*pc)();
}
fatal(f, a1, a2, a3, a4, a5, a6) char *f; {
printf(f, a1, a2, a3, a4, a5, a6);
printf("\n");
exit(1);
}